package com.swind.fast.modules.app.space.rent.component;

import com.swind.fast.common.api.vo.Result;

import org.springframework.stereotype.Component;
// import com.swind.fast.modules.app.industry.entity.customer.ScsApp1Factory;
// import com.swind.fast.modules.app.industry.service.customer.IScsApp1FactoryService;
import javax.servlet.http.HttpServletRequest;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
// import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Process;
import java.io.IOException;

import com.alibaba.fastjson.JSONObject;
// import com.swind.fast.modules.app.aircraft.entity.ScsAircraftUtilization;
// import com.swind.fast.modules.app.aircraft.service.IScsAircraftUtilizationService;

@Component
@Slf4j
public class SpaceInvokeComponent {

    // @Autowired
    // private IScsAircraftUtilizationService scsAircraftUtilizationService;

    public String parseAction(String filePath) {
        log.info("parseAction: {}", filePath);
        String result = null;

        // String file = "/home/prodmgr/projects/python/bigdata/demo/QUARTLY-UTILIZATION-REPORT-2021Q1-Aerdragon.docx";

        // String dir_path = "/home/prodmgr/projects/python/bigdata/demo";
        // String dir_path = "/opt/";
        try {
            String[] args = new String[] {"python", "/home/prodmgr/projects/python/bigdata/demo/worddocspace.py", filePath};

            log.info("starting....");

            Process proc = Runtime.getRuntime().exec(args);
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            String line = null;
            log.info("parsering...");

            while ((line = in.readLine()) != null) {
                log.info(line);
                JSONObject json = JSONObject.parseObject(line);

                // ScsAircraftUtilization airObj = (ScsAircraftUtilization) JSONObject.toJavaObject(json, ScsAircraftUtilization.class);

                // log.info("json {}", json);
                // log.info("json {}", json);
                result = json.getString("savePath");

                // scsAircraftUtilizationService.save(airObj);
            }
            in.close();
            proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return result;
    }

    // @Autowired
    // private IScsApp1FactoryService scsApp1FactoryService;

    // public Result<?> queryFactoryPageList(ScsApp1Factory factory,
    //             Integer pageNo,
    //             Integer pageSize,
    //             HttpServletRequest req) {

    //     QueryWrapper<ScsApp1Factory> queryWrapper = QueryGenerator.initQueryWrapper(factory, req.getParameterMap());
    //     Page<ScsApp1Factory> page = new Page<ScsApp1Factory>(pageNo, pageSize);
    //     IPage<ScsApp1Factory> pageList = scsApp1FactoryService.page(page, queryWrapper);

    //     return Result.OK(pageList);
    // }
}

